package bb.lanxing.calc.notify;

import android.content.Context;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;

public class VibratorHelper {
    public static final long[] VIBRATE_GPS_RECEIVED_PATTERN = {0, 500, 100, 300};
    public static final long[] VIBRATE_GPS_LOST_PATTERN = {0, 300, 200, 600};
    public static final long[] VIBRATE_ALERT_PATTERN = {50, 100, 50, 100};

    public static void vibrate(Context context, long[] pattern) {
        vibrate(context, pattern, -1);
    }

    public static void vibrate(Context context, long[] pattern, int repeat) {
        Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        if (vibrator == null) {
            return;
        }

        if (Build.VERSION.SDK_INT < 26) {
            vibrator.vibrate(pattern, repeat);
        } else {
            vibrator.vibrate(VibrationEffect.createWaveform(pattern, repeat));
        }
    }

    public static void cancel(Context context) {
        Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        if (vibrator == null) {
            return;
        }
        vibrator.cancel();
    }
}